package anr.desu.pmo.proyecto.model.dao.jpa;

import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.Query;
import anr.desu.pmo.proyecto.model.Area;
import anr.desu.pmo.proyecto.model.dao.AreaDAO;

public class JPAAreaDAO implements AreaDAO{

	private EntityManager em;
	
	public JPAAreaDAO(EntityManager em){
		this.em=em;
	}
	
	@Override
	public List<Area> findAll() {
		Query query=null;
		try{
			query=em.createQuery("Select o From Area o Order by o.sigla");
		}catch(Exception e){
			System.out.println("mensaje: "+e.getMessage());
		}
		return query.getResultList();
	}

	@Override
	public Area findById(Integer id) {
		Query query=em.createQuery("Select o From Area o Where o.idarea=?1");
		query.setParameter(1, id);
		return (Area)query.getSingleResult();
	}

	@Override
	public Area insert(Area o) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void update(Area o) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void delete(Area o) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public Area findBySigla(String sigla) {
		Query query=em.createQuery("Select o From Area o Where o.sigla=?1");
		query.setParameter(1, sigla);
		return (Area)query.getSingleResult();
	}

}
